package com.hm.jiaowuxitong.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.Properties;

public class DBUtil {
    public static JdbcTemplate jt=null;

    static {
        //将配置文件转换成输入流
        InputStream is = DBUtil.class
                .getClassLoader()
                .getResourceAsStream("com/hm/jiaowuxitong/util/druid.properties");

        //创建Properties对象
        Properties properties = new Properties();
        try {
            //将流文件导入properties
            properties.load(is);
            //Druid框架工程创建数据库连接池
            DataSource ds = DruidDataSourceFactory.createDataSource(properties);
            //将数据库连接池交给Spring框架进行连接管理
            jt = new JdbcTemplate(ds);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



}
